<template>
  <div class="order">
    <p class="suppliera">供应商结算单</p>

    <div class="searchtable">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="供应商名称">
          <el-input
            v-model="formInline.supplierName"
            placeholder="请输入供应商名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="结算状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="待确认" value="0" />
            <el-option label="未结算" value="2" />
            <el-option label="已结算" value="1" />
            <el-option label="全部" value="" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :cell-style="cellstyle"
        :header-cell-style="rowClass"
        :default-sort="{ prop: 'date', order: 'descending' }"
        :summary-method="getSummaries"
        show-summary
      >
        <el-table-column type="index" width="100" label="序号" />
        <el-table-column prop="supplierName" label="供应商名称" />
        <el-table-column prop="supplierId" label="供应商ID" />
        <el-table-column prop="statementNum" label="订单数量" />
        <el-table-column prop="totalWeight" label="总重量(kg)" />
        <el-table-column prop="statementPrice" label="结算金额" sortable />
        <el-table-column label="操作" fixed="right" width="200px">
          <template slot-scope="scope">
            <el-button type="primary" @click="detail()">明细</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        status: "",
        supplierName: ""
      },
      tableData: [{
          supplierName:"番禺水果店",
          supplierId:1663288,
          statementNum:130,
          totalWeight:198,
          statementPrice:13588
      },
      {
          supplierName:"番禺三鸟批发行",
          supplierId:16638668,
          statementNum:140,
          totalWeight:162,
          statementPrice:1258
      }
      ]
    };
  },
  methods: {
    // 跳转到明细
    detail(){
        this.$router.push({
            path:"orderdetail"
        })
    },
    cellstyle({ row, column, rowIndex, columnIndex }) {
      return "text-align:center";
    },
    rowClass({ row, rowIndex }) {
      return "text-align:center";
    },
    // 合计列
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      var allmoney = 0;
      data.map(item => {
        allmoney += Number(item.statementPrice);
        return allmoney;
      });
      columns.forEach((column, index) => {
        sums[4] = "汇总金额";
        sums[5] = allmoney;
      });

      return sums;
    },
  }
};
</script>

<style lang="scss" scoped>
.order {
  padding: 20px 40px;
  .suppliera {
    font-size: 22px;
    margin-bottom: 30px;
  }
    .table {
      // width: 800px;
      margin-top: 38px;
    }
}
</style>
